package com.dnjn.happiness.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.AppraiseTags;
import com.dnjn.happiness.biz.domain.vo.AppraiseTagsVO;
import com.dnjn.happiness.biz.service.IAppraiseTagsService;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 评价维度Controller
 *
 * @author happiness
 * @date 2024-03-15
 */
@Tag(name = "biz appraiseTags 评价维度", description = "评价维度")
@RestController
@RequestMapping("/appraiseTags")
public class AppraiseTagsController extends BaseController {
    @Autowired
    private IAppraiseTagsService appraiseTagsService;

    /**
     * 查询评价维度列表
     */
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseTags:list')")
    @Operation(summary = "list查询评价维度列表", description = "传参: deleted传 0 是已经添加的,1  是 下方没有添加的, 上方搜索框查询()")
    @PostMapping("/list")
    @Log(title = "biz", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody AppraiseTagsVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        AppraiseTags appraiseTags = new AppraiseTags();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseTags);
        Page page = Page.of(current, size);
        //todo
        Page<AppraiseTags> list = appraiseTagsService.selectTagList(page, vo);
        return success(list);
    }


    /**
     * 获取评价维度详细信息
     */
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseTags:query')")
    @Operation(summary = "get获取评价维度详细信息", description = "获取评价维度详细信息")
    @GetMapping(value = "/{appraiseTagsId}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("appraiseTagsId") Long appraiseTagsId) {
        return success(appraiseTagsService.getById(appraiseTagsId));
    }

    /**
     * 新增评价维度
     */
    @Log(title = "评价维度", businessType = BusinessType.INSERT)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseTags:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AppraiseTagsVO vo) {
        AppraiseTags appraiseTags = new AppraiseTags();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseTags);

        appraiseTags.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appraiseTagsService.save(appraiseTags));
    }

    /**
     * 修改评价维度
     */
    @Log(title = "评价维度", businessType = BusinessType.UPDATE)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseTags:edit')")
    @Operation(summary = "edit维度修改", description = " {\n" +
            "  \n" +
            "  \"deleted\": \"0\",\n" +
            "  \"appraiseTagsId\": 1\n" +
            "}")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody AppraiseTagsVO vo) {
        AppraiseTags appraiseTags = new AppraiseTags();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseTags);
        return toAjax(appraiseTagsService.updateById(appraiseTags));
    }

    /**
     * 删除评价维度
     */
    @Log(title = "评价维度", businessType = BusinessType.DELETE)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseTags:remove')")
    @DeleteMapping("/{appraiseagsIds}")
    public AjaxResult remove(@PathVariable Long[] appraiseagsIds) {
        return toAjax(appraiseTagsService.removeBatchByIds(Arrays.asList(appraiseagsIds)));
    }
}
